package com.isoft.airportsystem.service.impl.Flight;

import com.isoft.airportsystem.entity.flight.Airport;
import com.isoft.airportsystem.mapper.Flight.AirportMapper;
import com.isoft.airportsystem.service.flight.AirportService;
import com.isoft.airportsystem.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AirportServiceImpl implements AirportService {

    @Autowired
    private AirportMapper airportMapper;

    @Override
    public List<Airport> getAllAirports() {
        return airportMapper.selectAllAirports();
    }

    @Override
    public Airport getAirportByCode(String airportCode) {
        return airportMapper.selectByCode(airportCode);
    }

    @Override
    public List<Airport> queryAirports(Airport airport) {
        return airportMapper.selectAirportsByCondition(airport);
    }

    @Override
    public PageResult<Airport> queryAirportPage(int pageNum, int pageSize, Airport airport) {
        int offset = (pageNum - 1) * pageSize;
        List<Airport> list = airportMapper.selectAirportPage(offset, pageSize, airport);
        int total = airportMapper.countAirports(airport);
        return new PageResult<>(total, list);
    }

    @Override
    public boolean addAirport(Airport airport) {
        return airportMapper.insertAirport(airport) > 0;
    }

    @Override
    public boolean updateAirport(Airport airport) {
        return airportMapper.updateAirport(airport) > 0;
    }

    @Override
    public boolean deleteAirport(String airportCode) {
        return airportMapper.deleteAirport(airportCode) > 0;
    }
}